package com.lazy.demo1.handler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jsecode.net.common.INetListener;
import com.lazy.lib.util.DataQueue;

import io.netty.channel.Channel;

/**
 * TODO: 以后把队列处理部分提取出来
 * 
 * @author luodan
 *
 */
public class GidNetListener implements INetListener {
    private static final Logger logger = LoggerFactory.getLogger(GidNetListener.class);
    
    private static final int DEFAULT_CAPACITY = 500 * 1000; // 

    protected DataQueue dataQueue;
    // 队列的容量, 大于该大小, 将移除
    protected int capacity = DEFAULT_CAPACITY; //Integer.MAX_VALUE
    
    public GidNetListener(DataQueue dataQueue){
        this.dataQueue = dataQueue;
    }
    
    @Override
    public void messageReceived(Channel channel, Object obj){
        if (obj instanceof byte[]) {
            dataQueue.offerDataQueue((byte[])obj);
        }
    }
}
